﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DAL;
using BLL;
using Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace WeChat
{
    /// <summary>
    /// Actionregistration 的摘要说明
    /// </summary>
    public class Actionregistration : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            //卡号
            //string username = context.Request.QueryString["username"];
            //密码
            string password1 = context.Request.QueryString["password1"];
            //姓名
            string txtname = context.Request.QueryString["txtname"];
            //手机
            string phone = context.Request.QueryString["phone"];
            string username ='0'+ phone.Remove(0, 2);
            string sex = context.Request.QueryString["sex"];
            DateTime date = DateTime.Now;
            string pageType = context.Request.QueryString["pageType"];
            int numCount = IdentityBLL.getCount();
            numCount = numCount + 1;
            if (username == null || username == "")
            {
                username = numCount.ToString();
            }
            string RMG = "";
            JObject jo = new JObject();
            var ds = RegisteredusersBLL.getJh();
            string jh = ds.Tables[0].Rows[0]["xfjh"].ToString();
            switch (pageType)
            {
                case "Register":
                    int JudgeUser = RegisteredusersBLL.JudgeUser(username);
                    int user = 0;
                    if (JudgeUser != 0)
                    {
                        RMG = "2";
                    }
                    else if (user != 0)
                    {
                        RMG = "3";
                    }
                    else if (Convert.ToInt32(RegisteredusersBLL.Register(jh,txtname, phone, numCount, username, password1, date, sex)) > 0)
                    {
                        RegisteredusersBLL.userinfo(jh, "1", "&1");
                        RMG = "0";
                    }
                    else
                    {
                        RMG = "1";
                    }

                    break;
                default:

                    break;
            }
            context.Response.Write(RMG);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}